﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

public class TouchableList
{
    #region Singleton

    private static TouchableList instance = null;

    private TouchableList()
    {
    }

    public static TouchableList Instance
    {
        get
        {
            if (instance == null) instance = new TouchableList();
            return instance;
        }
    }

    #endregion

    #region Member Variables

    private List<ITouchable> touchables = new List<ITouchable>();

    #endregion

    #region Public Methods

    public void AddItem(ITouchable touchable)
    {
        if (!touchables.Contains(touchable))
        {
            touchables.Add(touchable);
            touchable.TouchEnabled = true;
        }
    }

    public List<ITouchable> GetItems()
    {
        return touchables;
    }

    public void Clear()
    {
        touchables.Clear();
    }

    public ITouchable FindTouchable(GameObject candidate)
    {
        foreach (ITouchable touchable in touchables)
        {
            if (touchable.GetColliderObject() == candidate)
            {
                return touchable;
            }
        }
        return null;
    }

    #endregion
}
